import {
    DIC
} from '@/const/dic';
import {
    timeFormatter
} from '../formatter';

function validateGreaterZeroWrapper(field) {
    return (rule, value, callback) => {
        if (value < 0) {
            callback(new Error(field + '不能小于0'));
        } else {
            callback();
        }
    };
}

function validateIsNumberWrapper(field) {
    return (rule, value, callback) => {
        if (isNaN(value)) {
            callback(new Error(field + '必须是数字'));
        } else {
            callback();
        }
    };
}
export const awardSettingTableOption = {
    border: true,
    index: true,
    selection: true,
    calcHeight: 380,
    columnBtn: false,
    searchClearable: false,
    tip: false,
    selectClearBtn: false,
    searchResetBtn: false,
    height: "auto",
    menu: true,
    menuAlign: "center",
    searchBtn: true,
    labelWidth: 120,
    refreshBtn: true,
    addBtn: false,
    dialogWidth: '800px',
    dialogHeight: 'auto',
    menuWidth: 180,
    editBtn: true,
    viewBtn: false,
    delBtn: false,
    column: [{
            "label": "开始金额(元)",
            "prop": "MinValue",
            "search": true,
            "type": "text",
            "fixed": false,
            "width": "auto",
            "row": false,
            "minWidth": "120",
            "readonly": false,
            "span": 12,
            "display": true,
            searchDefault: '',
            valueDefault: '',
            "rules": [{
                    "required": true,
                    "message": "请输入开始金额",
                    "trigger": "blur"
                }, {
                    validator: validateIsNumberWrapper('开始金额'),
                    "trigger": "blur"
                },
                {
                    validator: validateGreaterZeroWrapper('开始金额'),
                    "trigger": "blur"
                }
            ]
        },
        {
            "label": "结束金额(元)",
            "prop": "MaxValue",
            "search": true,
            "type": "text",
            "fixed": false,
            "width": "auto",
            "row": false,
            "minWidth": "120",
            "readonly": false,
            "span": 12,
            "display": true,
            "rules": [{
                    "required": true,
                    "message": "请输入结束金额",
                    "trigger": "blur"
                }, {
                    validator: validateIsNumberWrapper('结束金额'),
                    "trigger": "blur"
                },
                {
                    validator: validateGreaterZeroWrapper('结束金额'),
                    "trigger": "blur"
                }
            ]
        },
        {
            "label": "佣金(元)",
            "prop": "Award",
            "search": false,
            "type": "number",
            "fixed": false,
            precision: 2,
            "width": "auto",
            "row": false,
            "minWidth": "120",
            "readonly": false,
            "span": 12,
            "display": true,
            "rules": [{
                "required": true,
                "message": "请输入佣金",
                "trigger": "blur"
            }, {
                validator: validateGreaterZeroWrapper('佣金'),
                "trigger": "blur"
            }]
        },
        {
            "label": "创建时间",
            "prop": "CreateTime",
            "search": false,
            "type": "datetime",
            "fixed": false,
            "width": "160",
            "row": false,
            "minWidth": "120",
            "readonly": false,
            "span": 12,
            "display": false,
            "formatter": timeFormatter
        },
        {
            "label": "修改时间",
            "prop": "ModifyTime",
            "search": false,
            "type": "datetime",
            "fixed": false,
            "width": "160",
            "row": false,
            "minWidth": "120",
            "readonly": false,
            "span": 12,
            "display": false,
            "formatter": timeFormatter
        }
    ]
};
